#include<string>
#include<vector>
#include<array>
#include<unordered_map>
#include<algorithm>
#include<limits>
#include <stack>
#include<iostream>
#include<sstream>
#include<deque>
#define MOD 1000000007
class Solution {
public:
    std::array<long long,100001> sum{};
    int shortestSubarray(std::vector<int>& nums, int k) {
        int n = nums.size();
        std::deque<int> q;
        for(int i=0;i<n;i++)
        {
            sum[i+1] = sum[i] + nums[i];
        }
        bool flag = false;
        int ans = std::numeric_limits<int>::max();
        for (int i =0;i<=n;i++)
        {
            while (!q.empty() && sum[i]-sum[q.front()] >=k )
            {
                flag = true;
                ans = std::min(ans,i-q.front());
                q.pop_front();
            }
            while (!q.empty() && sum[q.back()] >= sum[i] )
            {
                q.pop_back();
            }
            q.push_back(i);
        }
        return flag?ans:-1;
    }
};
